home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / init.d / urandom < prev    next >
Text File  |  2009-09-07  |  2KB  |  79 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          urandom
  4. # Required-Start:    $remote_fs
  5. # Required-Stop:     $remote_fs
  6. # Default-Start:     S
  7. # Default-Stop:      0 6
  8. # Short-Description: Save and restore random seed between restarts.
  9. # Description:       This script saves the random seed between restarts.
  10. #                    It is called from the boot, halt and reboot scripts.
  11. ### END INIT INFO
  12.  
  13. [ -c /dev/urandom ] || exit 0
  14.  
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. SAVEDFILE=/var/lib/urandom/random-seed
  17. POOLSIZE=512
  18. [ -f /proc/sys/kernel/random/poolsize ] && POOLSIZE="$(cat /proc/sys/kernel/random/poolsize)"
  19. . /lib/init/vars.sh
  20.  
  21. . /lib/lsb/init-functions
  22.  
  23. do_status () {
  24.     if [ -f $SAVEDFILE ] ; then
  25.         return 0
  26.     else
  27.         return 4
  28.     fi
  29. }
  30.  
  31. case "$1" in
  32.   start|"")
  33.     [ "$VERBOSE" = no ] || log_action_begin_msg "Initializing random number generator"
  34.     # Load and then save $POOLSIZE bytes,
  35.     # which is the size of the entropy pool
  36.     if [ -f "$SAVEDFILE" ]
  37.     then
  38.         # Handle locally increased pool size
  39.         SAVEDSIZE="$(find "$SAVEDFILE" -printf "%s")"
  40.         if [ "$SAVEDSIZE" -gt "$POOLSIZE" ]
  41.         then
  42.             [ -w /proc/sys/kernel/random/poolsize ] && echo $POOLSIZE > /proc/sys/kernel/random/poolsize
  43.             POOLSIZE=$SAVEDSIZE
  44.         fi
  45.         cat "$SAVEDFILE" >/dev/urandom
  46.     fi
  47.     rm -f $SAVEDFILE
  48.     # Hm, why is the saved pool re-created at boot? [pere 2009-09-03]
  49.     umask 077
  50.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  51.     ES=$?
  52.     umask 022
  53.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  54.     ;;
  55.   stop)
  56.     # Carry a random seed from shut-down to start-up;
  57.     # see documentation in linux/drivers/char/random.c
  58.     [ "$VERBOSE" = no ] || log_action_begin_msg "Saving random seed"
  59.     umask 077
  60.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  61.     ES=$?
  62.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  63.     ;;
  64.   status)
  65.     do_status
  66.     exit $?
  67.     ;;
  68.   restart|reload|force-reload)
  69.     echo "Error: argument '$1' not supported" >&2
  70.     exit 3
  71.     ;;
  72.   *)
  73.     echo "Usage: urandom start|stop" >&2
  74.     exit 3
  75.     ;;
  76. esac
  77.  
  78. :
  79.